import DB from "@/common/sqlite.js";
export default {

	enterBookInfoDetailClick(index, index1) {

		var obItem = this.homeRankData[index].detailBeans[index1];
		var bookInfoStr = JSON.stringify(obItem)
		uni.navigateTo({
			url: '/pages/baseBusiness/bookInfoDetail/bookInfoDetailView?bookInfo=' + bookInfoStr
		})

	},
	enterMoreRankDataClick() {

		uni.navigateTo({
			url: '/pages/baseBusiness/novelList/novelListView'
		})

	},
	enterSearchDetailClick() {
		uni.navigateTo({
			url: '/pages/baseBusiness/bookSearch/bookSearchView'
		})
	},
	enterRankListClick() {
		uni.navigateTo({
			url: '/pages/baseBusiness/rankList/rankListView'
		})
	},
	enterClassificationListClick() {
		uni.navigateTo({
			url: '/pages/baseBusiness/classificationList/classificationListView'
		})
	},



	//  图片轮播 开始
	change(e) {
		this.current = e.detail.current
	},
	selectStyle(index) {
		this.dotsStyles = this.dotStyle[index]
		this.styleIndex = index
	},
	selectMode(mode, index) {
		this.mode = mode
		this.modeIndex = index
		this.styleIndex = -1
		this.dotsStyles = this.dotStyle[0]
	},
	clickItem(e) {
		this.swiperDotIndex = e
	},
	onBanner(index) {
		console.log(22222, index);
	},

	pictureRotationAutomatically() {
		// 自动轮播，简单地递增索引并循环
		this.swiperDotIndex = (this.swiperDotIndex + 1) % this.info.length;
	},


	// 新增表数据
	insertTableData() {
		let open = DB.isOpen();
		if (open) {
			let arr = [{
					name: '小明',
					id: 1001,
					age: 20,
					sex: "男",
				},
				{
					name: '萧红',
					id: 1002,
					age: 20,
					sex: "女",
				}
			]
			arr.map(item => {

				let sql = `'${item.name}','${item.age}','${item.sex}'`;
				let condition = "'user_name','age','sex'";
				// 新增 DB.insertTableData(表名, 对应表头列的数据)
				DB.insertTableData("user_info", sql, condition)
					.then(res => {
						// this.showToast("新增数据成功");
						console.log("新增数据成功", res);
						this.selectTableData();
					})
					.catch(error => {
						console.log("失败", JSON.stringify(error));
					});
			})
		} else {
			this.showToast("数据库未打开");
		}
	},

	// 查询表数据
	selectTableData() {
		let open = DB.isOpen();
		if (open) {
			// 查询表 DB.selectTableData(表名,查询条件列名,查询条件列值)
			DB.selectTableData("user_info")
				.then(res => {
					console.log("contact表数据", JSON.stringify(res));
					// this.listData = res;
				})
				.catch(error => {
					console.log("查询失败", error);
				});
		} else {
			this.showToast("数据库未打开");
		}
	},

	//  获取首页排行数据列表
	async getHomeRankingDataList() {

		var that = this;


		var paramCode = "";
		var localHttp = that.$http_url.getHttpUrl();
		that.homeRankData = [];
		var dataRes = await that.$sqlDBConfig.selectCollectionTableData2()
		this.$api.homeRankDatas(paramCode).then(res => {
			if (res.data.code == 200) {
				that.$refs.paging.complete();
				var homeRankData = res.data.data;
				homeRankData.forEach((item, index) => {
					item.detailBeans.forEach((item1, index1) => {
						item1.bookIconUrl = localHttp + "/images/" + item1.bookCode + "/" +
							item1.bookPic;
						item1.isCollection = false



						//  测试去掉-生产放开
						dataRes.forEach(function(item2, index2) {
							if (item2.bookcode == item1.bookCode) {
								item1.isCollection = true;
							}
						})
					})
				})
				that.homeRankData = homeRankData;
				that.homeRankData.forEach((item, index) => {
					item.detailBeans.forEach((item1, index1) => {
						let readInfo = uni.getStorageSync("readProcessData" + item1
							.bookCode);
						if (readInfo && readInfo.readProcessData && readInfo.readProcessData
							.detail) {
							// 添加阅读进度
							item1.progress = (readInfo.readProcessData.detail
								.progress ).toFixed(2);
						} else {
							item1.progress = 0;
						}
					})
				})
			}
		}).catch(error => {
			that.$refs.paging.complete();
		})




	},
	sexInfoChangeClick() {
		uni.navigateTo({
			url: '/pages/sex/sexSqlView?type=2'
		})
	},


}